home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WW3DKit / WW3DBox.m < prev    next >
Encoding:
Text File  |  1995-03-22  |  5.5 KB  |  226 lines

  1.  
  2. #import "WW3DBox.h"
  3. #import "RIBPointsPolygons.h"
  4.  
  5. @implementation WW3DBox
  6.  
  7. + initialize { return [WW3DBox setVersion:1], self; }
  8.  
  9. - assignPoints
  10. {
  11.   points[0][0] = xMin;
  12.   points[0][1] = yMax;
  13.   points[0][2] = zMax;
  14.  
  15.   points[1][0] = xMax;
  16.   points[1][1] = yMax;
  17.   points[1][2] = zMax;
  18.  
  19.   points[2][0] = xMax;
  20.   points[2][1] = yMax;
  21.   points[2][2] = zMin;
  22.  
  23.   points[3][0] = xMin;
  24.   points[3][1] = yMax;
  25.   points[3][2] = zMin;
  26.  
  27.   points[4][0] = xMin;
  28.   points[4][1] = yMin;
  29.   points[4][2] = zMax;
  30.  
  31.   points[5][0] = xMax;
  32.   points[5][1] = yMin;
  33.   points[5][2] = zMax;
  34.  
  35.   points[6][0] = xMax;
  36.   points[6][1] = yMin;
  37.   points[6][2] = zMin;
  38.  
  39.   points[7][0] = xMin;
  40.   points[7][1] = yMin;
  41.   points[7][2] = zMin;
  42.  
  43.   dirtyBoundingBox = TRUE;
  44.  
  45.   return self;
  46. }
  47.  
  48. - init
  49. {
  50.   [super init];
  51.  
  52.   nPolys = 6;
  53.  
  54.   nVerts[0] = nVerts[1] = nVerts[2] = nVerts[3] = nVerts[4] = nVerts[5] = 4;
  55.  
  56.   verts[0] = 3;   verts[1] = 2;   verts[2] = 6;   verts[3] = 7;
  57.   verts[4] = 2;   verts[5] = 1;   verts[6] = 5;   verts[7] = 6;
  58.   verts[8] = 1;   verts[9] = 0;   verts[10] = 4;  verts[11] = 5;
  59.   verts[12] = 0;  verts[13] = 3;  verts[14] = 7;  verts[15] = 4;
  60.   verts[16] = 7;  verts[17] = 6;  verts[18] = 5;  verts[19] = 4;
  61.   verts[20] = 0;  verts[21] = 1;  verts[22] = 2;  verts[23] = 3;
  62.  
  63.   xMin = -1.0;
  64.   xMax =  1.0;
  65.   yMin = -1.0;
  66.   yMax =  1.0;
  67.   zMin = -1.0;
  68.   zMax =  1.0;
  69.  
  70.   [self assignPoints];
  71.  
  72.   return self;
  73. }
  74.  
  75.  
  76. - setXMin:(RtFloat)newXMin xMax:(RtFloat)newXMax 
  77.      yMin:(RtFloat)newYMin yMax:(RtFloat)newYMax 
  78.      zMin:(RtFloat)newZMin zMax:(RtFloat)newZMax 
  79.      n:(int)newN tokens:(RtToken *)newTokens parms:(RtPointer *)newParms archiveVector:(char **)newArchiveVector
  80.      printfTypeVector:(int *)newPrintfTypeVector printfNVector:(int *)newPrintfNVector
  81. {  
  82.    id  boxObj;
  83.  
  84.  
  85.    xMin = newZMin;
  86.    xMax = newZMax;
  87.    yMin = newZMin;
  88.    yMax = newZMax;
  89.    zMin = newZMin;
  90.    zMax = newZMax;
  91.  
  92.    [ribCommandList empty];
  93.  
  94.    boxObj = [[RIBPointsPolygons alloc] init]; 
  95.    [boxObj setXMin:xMin xMax:xMax yMin:yMin yMax:yMax zMin:zMin zMax:zMax
  96.                     n:newN tokens:newTokens parms:newParms archiveVector:newArchiveVector printfTypeVector:newPrintfTypeVector printfNVector:newPrintfNVector];
  97.    [boxObj setMyShape:myShape];
  98.  
  99.    [ribCommandList insertObject:boxObj at:0];
  100.  
  101.    [self assignPoints];
  102.   
  103.    return self;
  104. }
  105.  
  106. - setXMin:(RtFloat)newXMin { xMin = newXMin; [self assignPoints]; return self; }
  107. - setXMax:(RtFloat)newXMax { xMax = newXMax; [self assignPoints]; return self; }
  108. - setYMin:(RtFloat)newYMin { yMin = newYMin; [self assignPoints]; return self; }
  109. - setYMax:(RtFloat)newYMax { yMax = newYMax; [self assignPoints]; return self; }
  110. - setZMin:(RtFloat)newZMin { zMin = newZMin; [self assignPoints]; return self; }
  111. - setZMax:(RtFloat)newZMax { zMax = newZMax; [self assignPoints]; return self; }
  112.  
  113. - (RtFloat)xMin { return xMin; }
  114. - (RtFloat)xMax { return xMax; }
  115. - (RtFloat)yMin { return yMin; }
  116. - (RtFloat)yMax { return yMax; }
  117. - (RtFloat)zMin { return zMin; }
  118. - (RtFloat)zMax { return zMax; }
  119.  
  120. // WavesWorld archiving:
  121. // writeEve:(NXStream *)stream
  122. // writeScene:(NXStream *)stream
  123.  
  124. - writeEve:(NXStream *)stream atTabLevel:(int)tab
  125. {
  126.     int  i;
  127.     
  128.     for (i = 0; i < tab; i++) {
  129.     NXPrintf(stream, "\t");
  130.     }
  131.     NXPrintf(stream, "WW3DBox %f %f %f %f %f %f", xMin, xMax, yMin, yMax, zMin, zMax);
  132.     return self;
  133. }
  134.  
  135. - writeScene:(NXStream *)stream atTabLevel:(int)tab
  136. {
  137.    return [self writeEve:stream atTabLevel:tab];
  138. }
  139.  
  140. - write3DTextScene:(NXStream *)stream atTabLevel:(int)tab index:(int)index time:(float)time until:(float)lastTime
  141. {
  142.    int  i;
  143.  
  144.  
  145.    for (i = 0; i < tab; i++)
  146.    {  NXPrintf(stream, "\t");
  147.    }
  148.  
  149.    NXPrintf(stream, "startShape %s; ", [[self class] name]);
  150.    // need tab
  151.    // need index (position in current list)
  152.    NXPrintf(stream, 
  153.         "EveCmd {Translate [expr { %d * $__text__(tabLength)}] [expr {$__text__(spacingFactor) * %d * $__text__(spacing) * $__text__(fontSize)}] 0 };\n", 
  154.             tab, index); 
  155.    NXPrintf(stream, "  EveCmd {WW3DText $__text__(fontName) $__text__(fontSize) {");
  156.    [self writeEve:stream atTabLevel:tab];
  157.    NXPrintf(stream, "} left;}\n");
  158.   NXPrintf(stream, "endShape;\n");
  159.  
  160.   return self;
  161. }
  162.  
  163. - writeInventorAtTime:(float)currentTime to:(NXStream *)stream atTabLevel:(int)tab
  164. {
  165.    int  i;
  166.  
  167.  
  168.    for (i = 0; i < tab; i++)
  169.    {  NXPrintf(stream, "\t");
  170.    }
  171.    NXPrintf(stream, "# ");
  172.    [self writeEve:stream atTabLevel:tab];
  173.    NXPrintf(stream, "\n");
  174.  
  175.    return [ribCommandList writeInventorAtTime:currentTime to:stream atTabLevel:tab];
  176. }
  177.  
  178.  
  179. #define typeVector "@ffffff"
  180. #define typeValues &ribCommandList, &xMin, &xMax, &yMin, &yMax, &zMin, &zMax
  181.  
  182. - read:(NXTypedStream *)stream 
  183. {
  184.     int version;
  185.     
  186.     [super read:stream];
  187.     version = NXTypedStreamClassVersion(stream,"WW3DBox");
  188.     if (version == 0) NXReadTypes(stream, "i", &version), version = 1;
  189.     if (version == 1)
  190.     {  NXReadTypes(stream, typeVector, typeValues);
  191.        NXReadArray(stream, "f", 6, boundingBox);
  192.        myShape = NXReadObject(stream);
  193.     }
  194.  
  195.     return self;
  196. }
  197.  
  198. - write:(NXTypedStream *)stream 
  199. {
  200.     [super write:stream];
  201.     NXWriteTypes(stream, typeVector, typeValues);
  202.     NXWriteArray(stream, "f", 6, boundingBox);
  203.     NXWriteObjectReference(stream, myShape);
  204.     return self;
  205. }
  206.  
  207. - (BOOL)theSameAs:otherRIBCommand
  208. {
  209.   // WAVE: really should try and return YES, but for now...
  210.   return NO;
  211. }
  212.  
  213. - (BOOL)isMoot
  214. {
  215.   return NO;
  216. }
  217.  
  218. - (BOOL)isMootStartingAt:(float)startTime endingAt:(float)endTime  {  return [self isMoot];  }
  219.  
  220. // boy, this is dumb... This is to get around the stupid warnings from the compiler - ask wave for details
  221. - class { return [super class]; }
  222.  
  223.  
  224.  
  225. @end
  226.